﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TaoC14P8
{
    public partial class GuessNumberGame : Form
    {
        int secretNumber;//target number
        int sentinel;//use as a sentinel
        int guessNumber = -1;//initial guessnumber to -1

        public GuessNumberGame()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (sentinel == 0)//generate the random number
            {
                Random randomNumber = new Random();
                secretNumber = randomNumber.Next(1, 1001);
                sentinel = -1;
            }
            guessNumber = Convert.ToInt32(textBox1.Text);//read the guess number

            if (guessNumber > secretNumber)
            {
                this.label1.Text = "Too High!";
                this.BackColor = System.Drawing.Color.Red;//change back color to red when the guess number is larger than the secret number
            }
            else if (guessNumber < secretNumber)
            {
                this.label1.Text = "Too Low!";
                this.BackColor = System.Drawing.Color.Blue;//change back color to blue when the guess number is smaller than the secret number
            }
            else if (guessNumber == secretNumber)
            {
                this.label1.Text = "You Win!";
                this.BackColor = System.Drawing.Color.Green;//change back color to green when the guess number is the same as the secret number
                this.textBox1.Enabled = false;//disable the text box
                this.button1.Visible = false;//invisible guess button
                this.button2.Visible = true;//visible play again button
            }//end if else

        }//end button click

        private void button2_Click(object sender, EventArgs e)//play again button
        {
            sentinel = 0;
            this.BackColor = System.Drawing.Color.LightGray;//initial the back color to gray
            this.label1.Text = "I have a number between 1 and 1000--can you guess my number? \r\n" + "Please enter your first guess.";//initial the textbox
            this.textBox1.Enabled = true;//enable it
            this.textBox1.Clear();//clear the text of the text box
            this.button2.Visible = false;//invisible play again button
            this.button1.Visible = true;//visible guess button


        }
    }//end class
}
